package com.zone.component_home

import android.Manifest
import com.zone.component_home.databinding.ActivityHomeBinding
import com.zone.component_home.viewmodel.HomeActivityVM
import com.zone.core.CoreApplication
import com.zone.core.base.BaseBindingViewModelActivity
import pub.devrel.easypermissions.AfterPermissionGranted
import pub.devrel.easypermissions.EasyPermissions

private const val PERMISSION_CAMERA = 1000 //权限的请求码唯一即可


class HomeActivity : BaseBindingViewModelActivity<ActivityHomeBinding, HomeActivityVM>() {
    val TAG = "HomeActivity"
    private lateinit var bind: ActivityHomeBinding
    private val perms = arrayOf(Manifest.permission.CAMERA) //一些权限用逗号隔开

    override fun inject() {
        HomeApp.appComponent.inject(this)
    }

    override fun initDataBinding(binding: ActivityHomeBinding) {
        super.initDataBinding(binding)
        bind = binding

    }

    override fun onEvent(eventId: Int) {
        super.onEvent(eventId)
        when (eventId) {
            0 -> {//切换
                bind.homePager.setCurrentItem(0, false)
            }

            1 -> {//切换
                bind.homePager.setCurrentItem(1, false)
            }

            2 -> {//切换
                bind.homePager.setCurrentItem(2, false)
            }

            3 -> {//切换
                bind.homePager.setCurrentItem(3, false)
            }
        }
    }

    @AfterPermissionGranted(PERMISSION_CAMERA)
    fun doSomethingWithCamera() {
        if (EasyPermissions.hasPermissions(this, *perms)) {

        } else {
            //没有权限去申请权限
            EasyPermissions.requestPermissions(
                this,
                "该权限仅是实现拍摄音视频，请通过权限否则不能使用某些功能！",
                PERMISSION_CAMERA,
                *perms
            )
        }
    }

}

